# -*- coding: utf-8 -*-
"""
Author:duan
Date: 2021/2/27 15:32
"""
import pika

credentials = pika.PlainCredentials('guest', 'guest')
connection = pika.BlockingConnection(pika.ConnectionParameters(host='127.0.0.1', credentials=credentials))
channel = connection.channel()
channel.exchange_declare(exchange='ex2', exchange_type='direct')
# 声明一个名为ex2的交换器，发布类型为指定路由分发
channel.basic_publish(exchange='ex2', routing_key='test1', body="only test1 will get this msg!")
# 往ex2中test1的路由分发消息
channel.basic_publish(exchange='ex2', routing_key='test2', body="only test2 will get this msg!")
# 往ex2中test2的路由分发消息
connection.close()
